import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'

// 园区管理
import yuanqu from './modules/yuanqu'
// 行车管理
import Car from './modules/Car'
// 物业费用管理
import Wuye from './modules/Wuye'
// 一体杆管理
import yiti from './modules/yiti'
// 系统管理
import xitong from './modules/xitong'

Vue.use(Router)

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '工作台', icon: 'dashboard' }
    }]
  },
  // 新增月卡管理页
  {
    path: '/Add-card',
    component: () => import('@/views/Car/Cartwo/Add-card'),
    hidden: true
  },
  // 新增企业页面
  {
    path: '/Add-qiye',
    component: () => import('@/views/yuanqu/qiye/Add-qiye'),
    hidden: true
  },
  // 查看合同页面
  {
    path: '/detail',
    component: () => import('@/views/yuanqu/qiye/detail'),
    hidden: true
  },
  yuanqu,
  Car,
  Wuye,
  yiti,
  xitong,

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
